local skel = fk.CreateSkill {
  name = "emo__renhe",
  tags = {Skill.Switch},
}

Fk:loadTranslationTable{
  ["emo__renhe"] = "人阖",
  [":emo__renhe"] = "转换技，出牌阶段限两次，你可以将一张牌当{阳：【铁锁连环】；阴：本回合你使用的上一张基本牌或普通锦囊牌}使用（无次数限制）。",

  ["emo__renhe_other"] = "人阖",
  ["#emo__renhe-active"] = "人阖：你可以将一张牌当【%arg】使用",
}

skel:addEffect("viewas", {
  anim_type = "switch",
  mute_card = false,
  prompt = function (self, player, selected_cards, selected)
    local name = "iron_chain"
    if player:getSwitchSkillState("emo__renhe") == fk.SwitchYin then
      name = player:getMark("emo__renhe_record-turn")
      if name == 0 then name = "?" end
    end
    return "#emo__renhe-active:::"..name
  end,
  card_filter = function (self, player, to_select, selected)
    return #selected == 0
  end,
  view_as = function (self, player, cards)
    if #cards ~= 1 then return nil end
    local name = "iron_chain"
    if player:getSwitchSkillState("emo__renhe") == fk.SwitchYin then
      name = player:getMark("emo__renhe_record-turn")
      if name == 0 then return nil end
    end
    local c = Fk:cloneCard(name)
    c.skillName = skel.name
    c:addSubcard(cards[1])
    return c
  end,
  before_use = function(self, player, use)
    use.extraUse = true
  end,
  times = function (self, player)
    return 2 - player:usedSkillTimes(skel.name, Player.HistoryPhase)
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) < 2
  end,
})

skel:addEffect(fk.CardUsing, {
  can_refresh = function(self, event, target, player, data)
    return target == player and (data.card.type == Card.TypeBasic or data.card:isCommonTrick())
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "emo__renhe_record-turn", data.card.name)
  end,
})


skel:addEffect("targetmod", {
  bypass_times = function(self, player, skill, scope, card)
    return card and table.contains(card.skillNames, skel.name)
  end,
})


return skel
